package org.jivesoftware.smackx.workgroup.settings;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
import org.xmlpull.v1.XmlPullParser;

public class ChatSettings extends IQ
{
  public static final int BOT_SETTINGS = 2;
  public static final String ELEMENT_NAME = "chat-settings";
  public static final int IMAGE_SETTINGS = 0;
  public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
  public static final int TEXT_SETTINGS = 1;
  private String key;
  private List settings;
  private int type = -1;

  public ChatSettings()
  {
    this.settings = new ArrayList();
  }

  public ChatSettings(String paramString)
  {
    setKey(paramString);
  }

  public void addSetting(ChatSetting paramChatSetting)
  {
    this.settings.add(paramChatSetting);
  }

  public ChatSetting getChatSetting(String paramString)
  {
    Iterator localIterator;
    Collection localCollection = getSettings();
    if (localCollection != null)
    {
      localIterator = localCollection.iterator();
      if (localIterator.hasNext())
        break label31;
    }
    Object localObject = null;
    while (true)
    {
      label31: ChatSetting localChatSetting;
      do
      {
        return localObject;
        localChatSetting = (ChatSetting)localIterator.next();
      }
      while (!(localChatSetting.getKey().equals(paramString)));
      localObject = localChatSetting;
    }
  }

  public String getChildElementXML()
  {
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("<").append("chat-settings").append(" xmlns=");
    localStringBuilder.append('"');
    localStringBuilder.append("http://jivesoftware.com/protocol/workgroup");
    localStringBuilder.append('"');
    if (this.key != null)
      localStringBuilder.append(" key=\"" + this.key + "\"");
    if (this.type != -1)
      localStringBuilder.append(" type=\"" + this.type + "\"");
    localStringBuilder.append("></").append("chat-settings").append("> ");
    return localStringBuilder.toString();
  }

  public ChatSetting getFirstEntry()
  {
    ChatSetting localChatSetting;
    if (this.settings.size() > 0)
      localChatSetting = (ChatSetting)this.settings.get(0);
    while (true)
    {
      return localChatSetting;
      localChatSetting = null;
    }
  }

  public Collection getSettings()
  {
    return this.settings;
  }

  public void setKey(String paramString)
  {
    this.key = paramString;
  }

  public void setType(int paramInt)
  {
    this.type = paramInt;
  }

  public static class InternalProvider
  implements IQProvider
  {
    private ChatSetting parseChatSetting(XmlPullParser paramXmlPullParser)
      throws Exception
    {
      int i = 0;
      String str1 = null;
      String str2 = null;
      int j = 0;
      while (true)
      {
        int k;
        do
          while (true)
          {
            while (true)
            {
              while (true)
              {
                if (i != 0)
                  return new ChatSetting(str1, str2, j);
                k = paramXmlPullParser.next();
                if ((k != 2) || (!("key".equals(paramXmlPullParser.getName()))))
                  break;
                str1 = paramXmlPullParser.nextText();
              }
              if ((k != 2) || (!("value".equals(paramXmlPullParser.getName()))))
                break;
              str2 = paramXmlPullParser.nextText();
            }
            if ((k != 2) || (!("type".equals(paramXmlPullParser.getName()))))
              break;
            j = Integer.parseInt(paramXmlPullParser.nextText());
          }
        while ((k != 3) || (!("chat-setting".equals(paramXmlPullParser.getName()))));
        i = 1;
      }
    }

    public IQ parseIQ(XmlPullParser paramXmlPullParser)
      throws Exception
    {
      if (paramXmlPullParser.getEventType() != 2)
        throw new IllegalStateException("Parser not in proper position, or bad XML.");
      ChatSettings localChatSettings = new ChatSettings();
      int i = 0;
      while (true)
      {
        int j;
        do
          while (true)
          {
            if (i != 0)
              return localChatSettings;
            j = paramXmlPullParser.next();
            if ((j != 2) || (!("chat-setting".equals(paramXmlPullParser.getName()))))
              break;
            localChatSettings.addSetting(parseChatSetting(paramXmlPullParser));
          }
        while ((j != 3) || (!("chat-settings".equals(paramXmlPullParser.getName()))));
        i = 1;
      }
    }
  }
}